package com.miyake.server;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class DsImage {
	@PrimaryKey 
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)  
	protected Key key;
	
	@Persistent
	protected Blob bin = null;

	@Persistent
	private String nodeKey;
	
	public String getEncodedKey() {
		return KeyFactory.keyToString(key);
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public byte[] getBin() {
		return bin.getBytes();
	}

	public void setBin(byte[] b) {
		bin = new Blob(b);
	}

	public void setNodeKey(String nodeKey) {
		this.nodeKey = nodeKey;
	}
	
	public String getNodeKey() {
		return this.nodeKey;
	}

	public String toRemoteObject() {
		return "fileServlet?type=image&key=" + this.getEncodedKey();//this.getNodeKey();
	}
}
